package com.guigu.qingcheng.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.guigu.qingcheng.mapper.TbCommentMapper;
import com.guigu.qingcheng.pojo.vo.TbCommentVo;
import com.guigu.qingcheng.service.TbCommentService;
import com.guigu.qingcheng.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class TbCommentServiceImpl implements TbCommentService {

    @Autowired(required = false)
    private TbCommentMapper tbCommentMapper;

    @Override
    public PageUtil<Map> pageComment(TbCommentVo commentVo, Integer pageNum, Integer pageSize) {
        Page<Map> maps = null;
        if (commentVo!=null){
            PageHelper.startPage(pageNum,pageSize);
            maps = (Page<Map>) tbCommentMapper.queryComment(commentVo);
        }else {
            PageHelper.startPage(pageNum,pageSize);
            maps = (Page<Map>) tbCommentMapper.queryAllComment();
        }
        PageUtil<Map> pageUtil=new PageUtil<>();
        pageUtil.setRows(maps.getResult());
        pageUtil.setTotal(maps.getTotal());
        return pageUtil;
    }
}
